package spark_class_study.spark_Graph
import org.apache.spark.api.java.JavaSparkContext.fromSparkContext
import org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark.graphx._
import org.apache.spark.rdd.RDD
object create_image {
  def main(args: Array[String]): Unit = {
      val sparkconf=new SparkConf().setAppName("创建图").setMaster("local[*]")
      val sc=new SparkContext(sparkconf)

    val   user:RDD[(Long,(String,String))]=sc.textFile("./data/vertices")
      .map{
        line =>  val lines=line.split(" ")
          (lines(0).toLong , (lines(1),lines(2)))
      }

    user.collect().foreach(println)


    val    relationships=sc.textFile("./data/edges")
      .map{
        line => val lines=line.split(" ")
          Edge(lines(0).toLong ,lines(1).toLong, lines(2))
      }

    val defaultUser=("john Doe","Missing")

    val graph_urelate=Graph(user,relationships,defaultUser)

    //  打印顶点rdd的内容
    graph_urelate.vertices.collect().foreach(println)
    //  打印边rdd的内容
    graph_urelate.edges.collect().foreach(println)






    sc.close()
  }

}
